<template>
  <p>
      页面加载后，第二个input元素自动获取焦点：</p>
      <input /><br /><br />
      <input v-focus /> <br><br>
      <input />
</template>

<script>
export default {
    directives: {
        focus: {
            mounted(el) {
                el.focus()
                el.value="获得焦点"
            }
        }
    }
}
</script>

<style scoped>
input:focus {
    background-color: black;
    color: white;
}
</style>